package org.advanced.pool;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author John.zhang
 * @version Id: ThreadPoolSerfs, v 1.0 2020/12/11 16:26 ZhiYong Exp $
 */
public class ThreadPoolSerfs extends ThreadPoolExecutor {

    public ThreadPoolSerfs(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
    }


    @Override
    protected void beforeExecute(Thread t, Runnable r) {
        //TODO 记录任务开始时间
    }

    @Override
    protected void afterExecute(Runnable r, Throwable t) {
        System.out.println("初始线程数：" + this.getPoolSize());
        System.out.println("核心线程数：" + this.getCorePoolSize());
        System.out.println("正在执行的任务数量：" + this.getActiveCount());
        System.out.println("已经执行的任务数量：" + this.getCompletedTaskCount());
        System.out.println("任务总数：" + this.getTaskCount());
        System.out.println("————————————————————————————————");
    }


}
